﻿#include "modbuscontrol.h"

ModbusControl::ModbusControl(QObject *parent)
    : QObject{parent}
{


}

ModbusControl::~ModbusControl()
{
    modbusClient->deleteLater();
}
// 设置连接参数
void ModbusControl::setConnectParameter(QString ip,QString port)
{

    setIpAddr(ip);
    setPortNumber(port);

    modbusClient->setConnectionParameter(QModbusDevice::NetworkAddressParameter,IpAddr());
    modbusClient->setConnectionParameter(QModbusDevice::NetworkPortParameter,PortNumber().toInt());

    // 设定响应时间
    modbusClient->setTimeout(500);
    // 重连次数
    modbusClient->setNumberOfRetries(3);

}

void ModbusControl::connectToPLC()
{
    // 连接PLC
    if(!modbusClient->connectDevice())
    {
        qDebug()<<"Cpp -- PLC连接失败"<<modbusClient->errorString();
    }
    else
    {
        qDebug()<<"Cpp -- PLC连接成功";
    }


}

void ModbusControl::write_modbus_tcp_HoldingRegisters(QString address, QString newValue)
{

    int w_addr = address.toInt() / 2;

    uint16_t value = newValue.toUShort();

    QModbusDataUnit writeUnit(QModbusDataUnit::HoldingRegisters,w_addr,1);

    writeUnit.setValue(0,value);

    if(auto* reply = modbusClient->sendWriteRequest(writeUnit,1))
    {
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply]()
            {
                if(reply->error() == QModbusDevice::NoError)
                {
                    qDebug()<<"写入寄存器成功";
                }
                else
                {
                    qDebug()<<"写入寄存器失败"<<reply->errorString();
                }

                reply->deleteLater();
            });
        }

        reply->deleteLater();
    }
    else
    {
        qDebug()<<"写入失败"<<modbusClient->errorString();
    }
}

void ModbusControl::write_modbus_tcp_HoldingRegisters_DW(QString address, QString newValue)
{
    int writeAdd = address.toInt() / 2;

    uint16_t write_regs[2] = {0};

    floatResolution(newValue,&write_regs[0],&write_regs[1]);

    if (modbusClient->state() != QModbusDevice::ConnectedState) {
        qDebug()<<"error : disConnectedState";
        return;
    }
    //写入到 holdaddress 地址    写两个寄存器
    QModbusDataUnit writeUnit(QModbusDataUnit::HoldingRegisters, writeAdd, 2);

    // 使用循环写入线圈的值
    // 将数据体对应位置的值 使用解析后的值进行赋值
    for (int i = 0; i < writeUnit.valueCount(); ++i) {
        writeUnit.setValue(i, write_regs[i]);
    }
    // 发送写入请求
    if(auto* reply = modbusClient->sendWriteRequest(writeUnit,1))
    {
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"写入双字寄存器成功";
                        }
                        else
                        {
                            qDebug()<<"写入双字寄存器失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }

        reply->deleteLater();
    }
    else
    {
        qDebug()<<"写入失败"<<modbusClient->errorString();
    }


}

void ModbusControl::floatResolution(QString setValue, uint16_t *high, uint16_t *low)
{
    float test = setValue.toFloat();

    // qDebug()<<"当前需要转换的数据为:  "<<test;

    uint8_t midValue [4] = {0};

    memcpy(midValue,&test,sizeof(float));   // 可用

    uint16_t midValue01[2] = {0};

    // qDebug()<<"8-高位: " <<midValue[3];
    // qDebug()<<"8-低位: " <<midValue[2];
    // qDebug()<<"8-次低位: " <<midValue[1];
    // qDebug()<<"8-低位: " <<midValue[0];

    midValue01[0] = (midValue[3] << 8| midValue[2]);
    midValue01[1] = (midValue[1] << 8| midValue[0]);

    // qDebug()<<"16-高位"<<midValue01[0];
    // qDebug()<<"16-低位"<<midValue01[1];

    *high = midValue01[0];
    *low = midValue01[1];
}

// 拼接数据 16位 -> 32位
float ModbusControl::combinationToFloat(quint16 valueH, quint16 valueL)
{
    float result = 0;

    uint32_t midValue = (static_cast<uint32_t>(valueH) << 16) | static_cast<uint32_t>(valueL);

    result = *(float*)&midValue;

    return result;

}

void ModbusControl::AutomaticPanel_OneKeyWriteParameter(QString knife, QString roller,
                                                        QString stress01, QString stress02, QString stress03,
                                                        QString fwdknife01, QString fwdknife02, QString fwdknife03,
                                                        QString backknife01, QString backknife02, QString backknife03)
{
    int w_addr =  3000 / 2;

    uint16_t write_regs[22] = {0};

    floatResolution(knife,&write_regs[0],&write_regs[1]);
    floatResolution(roller,&write_regs[2],&write_regs[3]);
    floatResolution(stress01,&write_regs[4],&write_regs[5]);
    floatResolution(stress02,&write_regs[6],&write_regs[7]);
    floatResolution(stress03,&write_regs[8],&write_regs[9]);
    floatResolution(fwdknife01,&write_regs[10],&write_regs[11]);
    floatResolution(fwdknife02,&write_regs[12],&write_regs[13]);
    floatResolution(fwdknife03,&write_regs[14],&write_regs[15]);
    floatResolution(backknife01,&write_regs[16],&write_regs[17]);
    floatResolution(backknife02,&write_regs[18],&write_regs[19]);
    floatResolution(backknife03,&write_regs[20],&write_regs[21]);

    QModbusDataUnit writeUnit(QModbusDataUnit::HoldingRegisters,w_addr,22);

    for (int i = 0; i < writeUnit.valueCount(); ++i) {
        writeUnit.setValue(i, write_regs[i]);
    }

    if(auto* reply = modbusClient->sendWriteRequest(writeUnit,1))
    {
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"一键写入配方参数成功";
                        }
                        else
                        {
                            qDebug()<<"一键写入配方参数失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }

        reply->deleteLater();
    }
    else
    {
        qDebug()<<"写入失败"<<modbusClient->errorString();
    }
}

void ModbusControl::readCurrentLocation()
{
    int readAdd = 2200 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,22);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取当前位置操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            knife_CurrLocation = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)),0,'f',2);
                            // qDebug()<<"刀盘当前位置  "<<knife_CurrLocation;
                            roller_CurrLocation = QString("%1").arg(combinationToFloat(resultUnit.value(2),resultUnit.value(3)),0,'f',2);
                            // qDebug()<<"胶辊当前位置  "<<roller_CurrLocation;
                            stress01_CurrLocation = QString("%1").arg(combinationToFloat(resultUnit.value(4),resultUnit.value(5)),0,'f',2);
                            // qDebug()<<"压力1当前位置  "<<stress01_CurrLocation;
                            stress02_CurrLocation = QString("%1").arg(combinationToFloat(resultUnit.value(6),resultUnit.value(7)),0,'f',2);
                            // qDebug()<<"压力2当前位置  "<<stress02_CurrLocation;
                            stress03_CurrLocation = QString("%1").arg(combinationToFloat(resultUnit.value(8),resultUnit.value(9)),0,'f',2);
                            // qDebug()<<"压力3当前位置  "<<stress03_CurrLocation;
                            f_knife01_CurrLocation = QString("%1").arg(combinationToFloat(resultUnit.value(10),resultUnit.value(11)),0,'f',2);
                            // qDebug()<<"前刀1当前位置  "<<f_knife01_CurrLocation;
                            f_knife02_CurrLocation = QString("%1").arg(combinationToFloat(resultUnit.value(12),resultUnit.value(13)),0,'f',2);
                            // qDebug()<<"前刀2当前位置  "<<f_knife02_CurrLocation;
                            f_knife03_CurrLocation = QString("%1").arg(combinationToFloat(resultUnit.value(14),resultUnit.value(15)),0,'f',2);
                            // qDebug()<<"前刀3当前位置  "<<f_knife03_CurrLocation;
                            b_knife01_CurrLocation = QString("%1").arg(combinationToFloat(resultUnit.value(16),resultUnit.value(17)),0,'f',2);
                            // qDebug()<<"后刀1当前位置  "<<b_knife01_CurrLocation;
                            b_knife02_CurrLocation = QString("%1").arg(combinationToFloat(resultUnit.value(18),resultUnit.value(19)),0,'f',2);
                            // qDebug()<<"后刀2当前位置  "<<b_knife02_CurrLocation;
                            b_knife03_CurrLocation = QString("%1").arg(combinationToFloat(resultUnit.value(20),resultUnit.value(21)),0,'f',2);
                            // qDebug()<<"后刀3当前位置  "<<b_knife03_CurrLocation;
                        }
                        else
                        {
                            qDebug()<<"读取当前位置操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }

}

void ModbusControl::readAimLocation()
{
    int readAdd = 3000 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,22);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取目标位置操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            knife_AimLocation = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)),0,'f',2);
                            // qDebug()<<"刀盘目标位置  "<<knife_CurrLocation;
                            roller_AimLocation = QString("%1").arg(combinationToFloat(resultUnit.value(2),resultUnit.value(3)),0,'f',2);
                            // qDebug()<<"胶辊目标位置  "<<roller_CurrLocation;
                            stress01_AimLocation = QString("%1").arg(combinationToFloat(resultUnit.value(4),resultUnit.value(5)),0,'f',2);
                            // qDebug()<<"压力1目标位置  "<<stress01_CurrLocation;
                            stress02_AimLocation = QString("%1").arg(combinationToFloat(resultUnit.value(6),resultUnit.value(7)),0,'f',2);
                            // qDebug()<<"压力2目标位置  "<<stress02_CurrLocation;
                            stress03_AimLocation = QString("%1").arg(combinationToFloat(resultUnit.value(8),resultUnit.value(9)),0,'f',2);
                            // qDebug()<<"压力3目标位置  "<<stress03_CurrLocation;
                            f_knife01_AimLocation = QString("%1").arg(combinationToFloat(resultUnit.value(10),resultUnit.value(11)),0,'f',2);
                            // qDebug()<<"前刀1目标位置  "<<f_knife01_CurrLocation;
                            f_knife02_AimLocation = QString("%1").arg(combinationToFloat(resultUnit.value(12),resultUnit.value(13)),0,'f',2);
                            // qDebug()<<"前刀2目标位置  "<<f_knife02_CurrLocation;
                            f_knife03_AimLocation = QString("%1").arg(combinationToFloat(resultUnit.value(14),resultUnit.value(15)),0,'f',2);
                            // qDebug()<<"前刀3目标位置  "<<f_knife03_CurrLocation;
                            b_knife01_AimLocation = QString("%1").arg(combinationToFloat(resultUnit.value(16),resultUnit.value(17)),0,'f',2);
                            // qDebug()<<"后刀1目标位置  "<<b_knife01_CurrLocation;
                            b_knife02_AimLocation = QString("%1").arg(combinationToFloat(resultUnit.value(18),resultUnit.value(19)),0,'f',2);
                            // qDebug()<<"后刀2目标位置  "<<b_knife02_CurrLocation;
                            b_knife03_AimLocation = QString("%1").arg(combinationToFloat(resultUnit.value(20),resultUnit.value(21)),0,'f',2);
                            // qDebug()<<"后刀3目标位置  "<<b_knife03_CurrLocation;
                        }
                        else
                        {
                            qDebug()<<"读取目标位置操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}

void ModbusControl::readStandbyLocation()
{
    int readAdd = 3200 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,22);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取待命点位置操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            knife_StandbyLocation = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)),0,'f',2);
                            // qDebug()<<"刀盘目标位置  "<<knife_CurrLocation;
                            roller_StandbyLocation = QString("%1").arg(combinationToFloat(resultUnit.value(2),resultUnit.value(3)),0,'f',2);
                            // qDebug()<<"胶辊目标位置  "<<roller_CurrLocation;
                            stress01_StandbyLocation = QString("%1").arg(combinationToFloat(resultUnit.value(4),resultUnit.value(5)),0,'f',2);
                            // qDebug()<<"压力1目标位置  "<<stress01_CurrLocation;
                            stress02_StandbyLocation = QString("%1").arg(combinationToFloat(resultUnit.value(6),resultUnit.value(7)),0,'f',2);
                            // qDebug()<<"压力2目标位置  "<<stress02_CurrLocation;
                            stress03_StandbyLocation = QString("%1").arg(combinationToFloat(resultUnit.value(8),resultUnit.value(9)),0,'f',2);
                            // qDebug()<<"压力3目标位置  "<<stress03_CurrLocation;
                            f_knife01_StandbyLocation = QString("%1").arg(combinationToFloat(resultUnit.value(10),resultUnit.value(11)),0,'f',2);
                            // qDebug()<<"前刀1目标位置  "<<f_knife01_CurrLocation;
                            f_knife02_StandbyLocation = QString("%1").arg(combinationToFloat(resultUnit.value(12),resultUnit.value(13)),0,'f',2);
                            // qDebug()<<"前刀2目标位置  "<<f_knife02_CurrLocation;
                            f_knife03_StandbyLocation = QString("%1").arg(combinationToFloat(resultUnit.value(14),resultUnit.value(15)),0,'f',2);
                            // qDebug()<<"前刀3目标位置  "<<f_knife03_CurrLocation;
                            b_knife01_StandbyLocation = QString("%1").arg(combinationToFloat(resultUnit.value(16),resultUnit.value(17)),0,'f',2);
                            // qDebug()<<"后刀1目标位置  "<<b_knife01_CurrLocation;
                            b_knife02_StandbyLocation = QString("%1").arg(combinationToFloat(resultUnit.value(18),resultUnit.value(19)),0,'f',2);
                            // qDebug()<<"后刀2目标位置  "<<b_knife02_CurrLocation;
                            b_knife03_StandbyLocation = QString("%1").arg(combinationToFloat(resultUnit.value(20),resultUnit.value(21)),0,'f',2);
                            // qDebug()<<"后刀3目标位置  "<<b_knife03_CurrLocation;
                        }
                        else
                        {
                            qDebug()<<"读取待命点位置操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}

void ModbusControl::readLocation()
{
    int readAdd = 3044 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,22);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取定位位置操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            knife_Location = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)),0,'f',2);
                            // qDebug()<<"刀盘目标位置  "<<knife_CurrLocation;
                            roller_Location = QString("%1").arg(combinationToFloat(resultUnit.value(2),resultUnit.value(3)),0,'f',2);
                            // qDebug()<<"胶辊目标位置  "<<roller_CurrLocation;
                            stress01_Location = QString("%1").arg(combinationToFloat(resultUnit.value(4),resultUnit.value(5)),0,'f',2);
                            // qDebug()<<"压力1目标位置  "<<stress01_CurrLocation;
                            stress02_Location = QString("%1").arg(combinationToFloat(resultUnit.value(6),resultUnit.value(7)),0,'f',2);
                            // qDebug()<<"压力2目标位置  "<<stress02_CurrLocation;
                            stress03_Location = QString("%1").arg(combinationToFloat(resultUnit.value(8),resultUnit.value(9)),0,'f',2);
                            // qDebug()<<"压力3目标位置  "<<stress03_CurrLocation;
                            f_knife01_Location = QString("%1").arg(combinationToFloat(resultUnit.value(10),resultUnit.value(11)),0,'f',2);
                            // qDebug()<<"前刀1目标位置  "<<f_knife01_CurrLocation;
                            f_knife02_Location = QString("%1").arg(combinationToFloat(resultUnit.value(12),resultUnit.value(13)),0,'f',2);
                            // qDebug()<<"前刀2目标位置  "<<f_knife02_CurrLocation;
                            f_knife03_Location = QString("%1").arg(combinationToFloat(resultUnit.value(14),resultUnit.value(15)),0,'f',2);
                            // qDebug()<<"前刀3目标位置  "<<f_knife03_CurrLocation;
                            b_knife01_Location = QString("%1").arg(combinationToFloat(resultUnit.value(16),resultUnit.value(17)),0,'f',2);
                            // qDebug()<<"后刀1目标位置  "<<b_knife01_CurrLocation;
                            b_knife02_Location = QString("%1").arg(combinationToFloat(resultUnit.value(18),resultUnit.value(19)),0,'f',2);
                            // qDebug()<<"后刀2目标位置  "<<b_knife02_CurrLocation;
                            b_knife03_Location = QString("%1").arg(combinationToFloat(resultUnit.value(20),resultUnit.value(21)),0,'f',2);
                            // qDebug()<<"后刀3目标位置  "<<b_knife03_CurrLocation;
                        }
                        else
                        {
                            qDebug()<<"读取定位位置操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}

void ModbusControl::readManualSpeedRate()
{
    int readAdd = 3448 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,2);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取手动速度比例操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            manualSpeedRate = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)),0,'f',2);
                        }
                        else
                        {
                            qDebug()<<"读取手动速度比例操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}

void ModbusControl::readTransducerSpeed()
{
    int readAdd = 2244 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,2);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取变频器速度操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            transducerSpeed = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)),0,'f',2);
                        }
                        else
                        {
                            qDebug()<<"读取变频器速度操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}

void ModbusControl::readErrCode()
{
    // 读取地址
    int readAdd = 2248/ 2 ;
    // 接收读取结果
    // uint16_t readvalue = 0;
    // 创建一个读取寄存器数据单位  [寄存器类型，读取地址，数量]
    QModbusDataUnit readUnit(QModbusDataUnit::HoldingRegisters,readAdd,9);
    // 发送读取寄存器请求
    if(auto* reply = (modbusClient->sendReadRequest(readUnit,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取错位代码操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            stress01_ErrCode = QString("%1").arg(resultUnit.value(0));
                            // qDebug()<<"压力1错误代码  "<<stress01_ErrCode;
                            stress02_ErrCode = QString("%1").arg(resultUnit.value(1));
                            // qDebug()<<"压力2错误代码  "<<stress02_ErrCode;
                            stress03_ErrCode = QString("%1").arg(resultUnit.value(2));
                            // qDebug()<<"压力3错误代码  "<<stress03_ErrCode;
                            f_knife01_ErrCode = QString("%1").arg(resultUnit.value(3));
                            // qDebug()<<"前刀1错误代码  "<<f_knife01_ErrCode;
                            f_knife02_ErrCode = QString("%1").arg(resultUnit.value(4));
                            // qDebug()<<"前刀2错误代码  "<<f_knife02_ErrCode;
                            f_knife03_ErrCode = QString("%1").arg(resultUnit.value(5));
                            // qDebug()<<"前刀3错误代码  "<<f_knife03_ErrCode;
                            b_knife01_ErrCode = QString("%1").arg(resultUnit.value(6));
                            // qDebug()<<"后刀1错误代码  "<<b_knife01_ErrCode;
                            b_knife02_ErrCode = QString("%1").arg(resultUnit.value(7));
                            // qDebug()<<"后刀2错误代码  "<<b_knife02_ErrCode;
                            b_knife03_ErrCode = QString("%1").arg(resultUnit.value(8));
                            // qDebug()<<"后刀3错误代码  "<<b_knife03_ErrCode;
                        }
                        else
                        {
                            qDebug()<<"读取错误代码操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}

void ModbusControl::readIO_DisInput()
{
    int readAdd = 0;
    // 创建读取数据体		【离散型输入，地址，数量】
    QModbusDataUnit readUnit(QModbusDataUnit::DiscreteInputs,readAdd,13);
    // 发送读取请求
    if(auto* reply = (modbusClient->sendReadRequest(readUnit,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取IO - 离散输入操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            if(resultUnit.value(0) == 1)
                            {
                                knifeA = true;
                            }
                            else if(resultUnit.value(0) == 0)
                            {
                                knifeA = false;
                            }
                            if(resultUnit.value(1) == 1)
                            {
                                knifeB = true;
                            }
                            else if(resultUnit.value(1) == 0)
                            {
                                knifeB = false;
                            }
                            if(resultUnit.value(2) == 1)
                            {
                                rollerA = true;
                            }
                            else if(resultUnit.value(2) == 0)
                            {
                                rollerA = false;
                            }
                            if(resultUnit.value(3) == 1)
                            {
                                rollerB = true;
                            }
                            else if(resultUnit.value(3) == 0)
                            {
                                rollerB = false;
                            }
                            if(resultUnit.value(4) == 1)
                            {
                                scramBtn = true;
                            }
                            else if(resultUnit.value(4) == 0)
                            {
                                scramBtn = false;
                            }
                            if(resultUnit.value(5) == 1)
                            {
                                rollerOrigin = true;
                                // qDebug()<<"胶辊原点: "<<true;
                            }
                            else if(resultUnit.value(5) == 0)
                            {
                                rollerOrigin = false;
                                // qDebug()<<"胶辊原点: "<<false;
                            }
                            if(resultUnit.value(6) == 1)
                            {
                                knifeUpLmt = true;
                                // qDebug()<<"刀盘上限位: "<<true;
                            }
                            else if(resultUnit.value(6) == 0)
                            {
                                knifeUpLmt = false;
                                // qDebug()<<"刀盘上限位: "<<false;
                            }
                            if(resultUnit.value(7) == 1)
                            {
                                knifeDownLmt = true;
                                // qDebug()<<"刀盘下限位: "<<true;
                            }
                            else if(resultUnit.value(7) == 0)
                            {
                                knifeDownLmt = false;
                                // qDebug()<<"刀盘下限位: "<<false;
                            }
                            if(resultUnit.value(8) == 1)
                            {
                                transducerWarnning = true;
                                // qDebug()<<"变频器报警: "<<true;
                            }
                            else if(resultUnit.value(8) == 0)
                            {
                                transducerWarnning = false;
                                // qDebug()<<"变频器报警: "<<false;
                            }
                            if(resultUnit.value(9) == 1)
                            {
                                knifeUpBtn = true;
                            }
                            else if(resultUnit.value(9) == 0)
                            {
                                knifeUpBtn = false;
                            }
                            if(resultUnit.value(10) == 1)
                            {
                                knifeDownBtn = true;
                            }
                            else if(resultUnit.value(10) == 0)
                            {
                                knifeDownBtn = false;
                            }
                            if(resultUnit.value(11) == 1)
                            {
                                rollerUpBtn = true;
                            }
                            else if(resultUnit.value(11) == 0)
                            {
                                rollerUpBtn = false;
                            }
                            if(resultUnit.value(12) == 1)
                            {
                                rollerDownBtn = true;
                            }
                            else if(resultUnit.value(12) == 0)
                            {
                                rollerDownBtn = false;
                            }
                        }
                        else
                        {
                            qDebug()<<"读取IO - 离散输入操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}

void ModbusControl::readIO_Coils()
{
    // 读取地址
    int readAdd = 0;
    // ModBus数据单位 [线圈，地址，数量]
    QModbusDataUnit readUnit(QModbusDataUnit::Coils,readAdd,7);
    // 向PLC 发送读取请求  [数据体，数量]
    if(auto* reply = (modbusClient->sendReadRequest(readUnit,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取IO - 线圈输入操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            if(resultUnit.value(0) == 1)
                            {
                                knifeUpSignal = true;
                            }
                            else if(resultUnit.value(0) == 0)
                            {
                                knifeUpSignal = false;
                            }
                            if(resultUnit.value(1) == 1)
                            {
                                knifeDownSignal = true;
                            }
                            else if(resultUnit.value(1) == 0)
                            {
                                knifeDownSignal = false;
                            }
                            if(resultUnit.value(2) == 1)
                            {
                                rollerUpSignal = true;
                            }
                            else if(resultUnit.value(2) == 0)
                            {
                                rollerUpSignal = false;
                            }
                            if(resultUnit.value(3) == 1)
                            {
                                rollerDownSignal = true;
                            }
                            else if(resultUnit.value(3) == 0)
                            {
                                rollerDownSignal = false;
                            }
                            if(resultUnit.value(4) == 1)
                            {
                                manualControlSignal = true;
                            }
                            else if(resultUnit.value(4) == 0)
                            {
                                manualControlSignal = false;
                            }
                            if(resultUnit.value(5) == 1)
                            {
                                runningSignal = true;
                            }
                            else if(resultUnit.value(5) == 0)
                            {
                                runningSignal = false;
                            }
                            if(resultUnit.value(6) == 1)
                            {
                                warnningSignal = true;
                                // qDebug()<<"报警信号: "<<true;
                            }
                            else if(resultUnit.value(6) == 0)
                            {
                                warnningSignal = false;
                                // qDebug()<<"报警信号: "<<false;
                            }

                        }
                        else
                        {
                            qDebug()<<"读取IO - 线圈操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}

void ModbusControl::readAutoAndManualSpeed()
{
    int readAdd = 3432 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,8);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取手动自动速度操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            stress_ManualSpeed = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)),0,'f',2);
                            // qDebug()<<"刀盘目标位置  "<<knife_CurrLocation;
                            stress_AutoSpeed = QString("%1").arg(combinationToFloat(resultUnit.value(2),resultUnit.value(3)),0,'f',2);
                            // qDebug()<<"胶辊目标位置  "<<roller_CurrLocation;
                            knife_ManualSpeed = QString("%1").arg(combinationToFloat(resultUnit.value(4),resultUnit.value(5)),0,'f',2);
                            // qDebug()<<"压力1目标位置  "<<stress01_CurrLocation;
                            knife_AutoSpeed = QString("%1").arg(combinationToFloat(resultUnit.value(6),resultUnit.value(7)),0,'f',2);
                        }
                        else
                        {
                            qDebug()<<"读取手动自动速度操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
    }
}

void ModbusControl::readB_KnifeOffset()
{
    int readAdd = 3332 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,6);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取后刀偏移量操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            b_knife01_Offset = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)),0,'f',2);
                            // qDebug()<<"刀盘目标位置  "<<knife_CurrLocation;
                            b_knife02_Offset = QString("%1").arg(combinationToFloat(resultUnit.value(2),resultUnit.value(3)),0,'f',2);
                            // qDebug()<<"胶辊目标位置  "<<roller_CurrLocation;
                            b_knife03_Offset = QString("%1").arg(combinationToFloat(resultUnit.value(4),resultUnit.value(5)),0,'f',2);
                        }
                        else
                        {
                            qDebug()<<"读取后刀偏移量操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
    }
}

void ModbusControl::readOriginLocation()
{
    int readAdd = 3500 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,22);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取原点位置操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            knife_OriginLocation = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)),0,'f',2);
                            // qDebug()<<"刀盘目标位置  "<<knife_CurrLocation;
                            roller_OriginLocation = QString("%1").arg(combinationToFloat(resultUnit.value(2),resultUnit.value(3)),0,'f',2);
                            // qDebug()<<"胶辊目标位置  "<<roller_CurrLocation;
                            stress01_OriginLocation = QString("%1").arg(combinationToFloat(resultUnit.value(4),resultUnit.value(5)),0,'f',2);
                            // qDebug()<<"压力1目标位置  "<<stress01_CurrLocation;
                            stress02_OriginLocation = QString("%1").arg(combinationToFloat(resultUnit.value(6),resultUnit.value(7)),0,'f',2);
                            // qDebug()<<"压力2目标位置  "<<stress02_CurrLocation;
                            stress03_OriginLocation = QString("%1").arg(combinationToFloat(resultUnit.value(8),resultUnit.value(9)),0,'f',2);
                            // qDebug()<<"压力3目标位置  "<<stress03_CurrLocation;
                            f_knife01_OriginLocation = QString("%1").arg(combinationToFloat(resultUnit.value(10),resultUnit.value(11)),0,'f',2);
                            // qDebug()<<"前刀1目标位置  "<<f_knife01_CurrLocation;
                            f_knife02_OriginLocation = QString("%1").arg(combinationToFloat(resultUnit.value(12),resultUnit.value(13)),0,'f',2);
                            // qDebug()<<"前刀2目标位置  "<<f_knife02_CurrLocation;
                            f_knife03_OriginLocation = QString("%1").arg(combinationToFloat(resultUnit.value(14),resultUnit.value(15)),0,'f',2);
                            // qDebug()<<"前刀3目标位置  "<<f_knife03_CurrLocation;
                            b_knife01_OriginLocation = QString("%1").arg(combinationToFloat(resultUnit.value(16),resultUnit.value(17)),0,'f',2);
                            // qDebug()<<"后刀1目标位置  "<<b_knife01_CurrLocation;
                            b_knife02_OriginLocation = QString("%1").arg(combinationToFloat(resultUnit.value(18),resultUnit.value(19)),0,'f',2);
                            // qDebug()<<"后刀2目标位置  "<<b_knife02_CurrLocation;
                            b_knife03_OriginLocation = QString("%1").arg(combinationToFloat(resultUnit.value(20),resultUnit.value(21)),0,'f',2);
                            // qDebug()<<"后刀3目标位置  "<<b_knife03_CurrLocation;
                        }
                        else
                        {
                            qDebug()<<"读取原点位置操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}

void ModbusControl::readLimitLocation()
{
    int readAdd = 3344 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,44);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取限位位置操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            knife_UpLimit = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)),0,'f',2);
                            knife_DownLimit = QString("%1").arg(combinationToFloat(resultUnit.value(2),resultUnit.value(3)),0,'f',2);
                            roller_UpLimit = QString("%1").arg(combinationToFloat(resultUnit.value(4),resultUnit.value(5)),0,'f',2);
                            roller_DownLimit = QString("%1").arg(combinationToFloat(resultUnit.value(6),resultUnit.value(7)),0,'f',2);
                            stress01_F_Limit = QString("%1").arg(combinationToFloat(resultUnit.value(8),resultUnit.value(9)),0,'f',2);
                            stress01_B_Limit = QString("%1").arg(combinationToFloat(resultUnit.value(10),resultUnit.value(11)),0,'f',2);
                            stress02_F_Limit = QString("%1").arg(combinationToFloat(resultUnit.value(12),resultUnit.value(13)),0,'f',2);
                            stress02_B_Limit = QString("%1").arg(combinationToFloat(resultUnit.value(14),resultUnit.value(15)),0,'f',2);
                            stress03_F_Limit = QString("%1").arg(combinationToFloat(resultUnit.value(16),resultUnit.value(17)),0,'f',2);
                            stress03_B_Limit = QString("%1").arg(combinationToFloat(resultUnit.value(18),resultUnit.value(19)),0,'f',2);
                            f_knife01_UpLimit = QString("%1").arg(combinationToFloat(resultUnit.value(20),resultUnit.value(21)),0,'f',2);
                            f_knife01_DownLimit = QString("%1").arg(combinationToFloat(resultUnit.value(22),resultUnit.value(23)),0,'f',2);
                            f_knife02_UpLimit = QString("%1").arg(combinationToFloat(resultUnit.value(24),resultUnit.value(25)),0,'f',2);
                            f_knife02_DownLimit = QString("%1").arg(combinationToFloat(resultUnit.value(26),resultUnit.value(27)),0,'f',2);
                            f_knife03_UpLimit = QString("%1").arg(combinationToFloat(resultUnit.value(28),resultUnit.value(29)),0,'f',2);
                            f_knife03_DownLimit = QString("%1").arg(combinationToFloat(resultUnit.value(30),resultUnit.value(31)),0,'f',2);
                            b_knife01_UpLimit = QString("%1").arg(combinationToFloat(resultUnit.value(32),resultUnit.value(33)),0,'f',2);
                            b_knife01_DownLimit = QString("%1").arg(combinationToFloat(resultUnit.value(34),resultUnit.value(35)),0,'f',2);
                            b_knife02_UpLimit = QString("%1").arg(combinationToFloat(resultUnit.value(36),resultUnit.value(37)),0,'f',2);
                            b_knife02_DownLimit = QString("%1").arg(combinationToFloat(resultUnit.value(38),resultUnit.value(39)),0,'f',2);
                            b_knife03_UpLimit = QString("%1").arg(combinationToFloat(resultUnit.value(40),resultUnit.value(41)),0,'f',2);
                            b_knife03_DownLimit = QString("%1").arg(combinationToFloat(resultUnit.value(42),resultUnit.value(43)),0,'f',2);
                        }
                        else
                        {
                            qDebug()<<"读取限位位置操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}

void ModbusControl::readCompensate()
{
    int readAdd = 3244 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,44);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取限位位置操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            knife_UpCpst = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)),0,'f',2);
                            knife_DownCpst = QString("%1").arg(combinationToFloat(resultUnit.value(2),resultUnit.value(3)),0,'f',2);
                            roller_UpCpst = QString("%1").arg(combinationToFloat(resultUnit.value(4),resultUnit.value(5)),0,'f',2);
                            roller_DownCpst = QString("%1").arg(combinationToFloat(resultUnit.value(6),resultUnit.value(7)),0,'f',2);
                            stress01_F_Cpst = QString("%1").arg(combinationToFloat(resultUnit.value(8),resultUnit.value(9)),0,'f',2);
                            stress01_B_Cpst = QString("%1").arg(combinationToFloat(resultUnit.value(10),resultUnit.value(11)),0,'f',2);
                            stress02_F_Cpst = QString("%1").arg(combinationToFloat(resultUnit.value(12),resultUnit.value(13)),0,'f',2);
                            stress02_B_Cpst = QString("%1").arg(combinationToFloat(resultUnit.value(14),resultUnit.value(15)),0,'f',2);
                            stress03_F_Cpst = QString("%1").arg(combinationToFloat(resultUnit.value(16),resultUnit.value(17)),0,'f',2);
                            stress03_B_Cpst = QString("%1").arg(combinationToFloat(resultUnit.value(18),resultUnit.value(19)),0,'f',2);
                            f_knife01_UpCpst = QString("%1").arg(combinationToFloat(resultUnit.value(20),resultUnit.value(21)),0,'f',2);
                            f_knife01_DownCpst = QString("%1").arg(combinationToFloat(resultUnit.value(22),resultUnit.value(23)),0,'f',2);
                            f_knife02_UpCpst = QString("%1").arg(combinationToFloat(resultUnit.value(24),resultUnit.value(25)),0,'f',2);
                            f_knife02_DownCpst = QString("%1").arg(combinationToFloat(resultUnit.value(26),resultUnit.value(27)),0,'f',2);
                            f_knife03_UpCpst = QString("%1").arg(combinationToFloat(resultUnit.value(28),resultUnit.value(29)),0,'f',2);
                            f_knife03_DownCpst = QString("%1").arg(combinationToFloat(resultUnit.value(30),resultUnit.value(31)),0,'f',2);
                            b_knife01_UpCpst = QString("%1").arg(combinationToFloat(resultUnit.value(32),resultUnit.value(33)),0,'f',2);
                            b_knife01_DownCpst = QString("%1").arg(combinationToFloat(resultUnit.value(34),resultUnit.value(35)),0,'f',2);
                            b_knife02_UpCpst = QString("%1").arg(combinationToFloat(resultUnit.value(36),resultUnit.value(37)),0,'f',2);
                            b_knife02_DownCpst = QString("%1").arg(combinationToFloat(resultUnit.value(38),resultUnit.value(39)),0,'f',2);
                            b_knife03_UpCpst = QString("%1").arg(combinationToFloat(resultUnit.value(40),resultUnit.value(41)),0,'f',2);
                            b_knife03_DownCpst = QString("%1").arg(combinationToFloat(resultUnit.value(42),resultUnit.value(43)),0,'f',2);
                        }
                        else
                        {
                            qDebug()<<"读取限位位置操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}

void ModbusControl::readWarningSignal()
{
    // 测试数据（3000）   实际使用地址: 2060
    int readAdd = 2060 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,2);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            qDebug()<<"读取报警信号操作成功";
                            const QModbusDataUnit resultUnit = reply->result();
                            // QString testresult = QString("%1").arg(resultUnit.value(0));
                            // qDebug()<<"测试结果  "<<testresult;
                            QByteArray midArray01;
                            QDataStream stream1(&midArray01, QIODevice::WriteOnly);
                            stream1.setByteOrder(QDataStream::BigEndian); // 设置字节顺序，如果需要的话
                            stream1<<resultUnit.value(0);
                            QString res = "";
                            // 输出 QByteArray 中的每一个字节
                            for (int i = 0; i < midArray01.size(); ++i) {
                                // 将每个字节转换为二进制形式的字符串，并打印
                                QString binaryString = QString::number(static_cast<unsigned char>(midArray01[i]), 2).rightJustified(8, '0');
                                // qDebug() << "Byte" << i << ":" << binaryString;
                                res += binaryString;
                            }
                            if(res.at(7) == '1')
                            {
                                knife_Up_SLmt = true;
                            }
                            else if(res.at(7) == '0')
                            {
                                knife_Up_SLmt = false;
                            }
                            if(res.at(6) == '1')
                            {
                                knife_Down_SLmt = true;
                            }
                            else if(res.at(6) == '0')
                            {
                                knife_Down_SLmt = false;
                            }
                            if(res.at(5) == '1')
                            {
                                roller_Up_SLmt = true;
                            }
                            else if(res.at(5) == '0')
                            {
                                roller_Up_SLmt = false;
                            }
                            if(res.at(4) == '1')
                            {
                                roller_Down_SLmt = true;
                            }
                            else if(res.at(4) == '0')
                            {
                                roller_Down_SLmt = false;
                            }
                            if(res.at(3) == '1')
                            {
                                stress01_F_SLmt = true;
                            }
                            else if(res.at(3) == '0')
                            {
                                stress01_F_SLmt = false;
                            }
                            if(res.at(2) == '1')
                            {
                                stress01_B_SLmt = true;
                            }
                            else if(res.at(2) == '0')
                            {
                                stress01_B_SLmt = false;
                            }
                            if(res.at(1) == '1')
                            {
                                stress02_F_SLmt = true;
                            }
                            else if(res.at(1) == '0')
                            {
                                stress02_F_SLmt = false;
                            }
                            if(res.at(0) == '1')
                            {
                                stress02_B_SLmt = true;
                            }
                            else if(res.at(0) == '0')
                            {
                                stress02_B_SLmt = false;
                            }
                            if(res.at(15) == '1')
                            {
                                stress03_F_SLmt = true;
                            }
                            else if(res.at(15) == '0')
                            {
                                stress03_F_SLmt = false;
                            }
                            if(res.at(14) == '1')
                            {
                                stress03_B_SLmt = true;
                            }
                            else if(res.at(14) == '0')
                            {
                                stress03_B_SLmt = false;
                            }
                            if(res.at(13) == '1')
                            {
                                f_knife01_Up_SLmt = true;
                            }
                            else if(res.at(13) == '0')
                            {
                                f_knife01_Up_SLmt = false;
                            }
                            if(res.at(12) == '1')
                            {
                                f_knife01_Down_SLmt = true;
                            }
                            else if(res.at(12) == '0')
                            {
                                f_knife01_Down_SLmt = false;
                            }
                            if(res.at(11) == '1')
                            {
                                f_knife02_Up_SLmt = true;
                            }
                            else if(res.at(11) == '0')
                            {
                                f_knife02_Up_SLmt = false;
                            }
                            if(res.at(10) == '1')
                            {
                                f_knife02_Down_SLmt = true;
                            }
                            else if(res.at(10) == '0')
                            {
                                f_knife02_Down_SLmt = false;
                            }
                            if(res.at(9) == '1')
                            {
                                f_knife03_Up_SLmt = true;
                            }
                            else if(res.at(9) == '0')
                            {
                                f_knife03_Up_SLmt = false;
                            }
                            if(res.at(8) == '1')
                            {
                                f_knife03_Down_SLmt = true;
                            }
                            else if(res.at(8) == '0')
                            {
                                f_knife03_Down_SLmt = false;
                            }

                            QByteArray midArray02;
                            QDataStream stream2(&midArray02, QIODevice::WriteOnly);
                            stream2.setByteOrder(QDataStream::BigEndian); // 设置字节顺序，如果需要的话
                            stream2<<resultUnit.value(1);

                            QString res2 = "";

                            // 输出 QByteArray 中的每一个字节
                            for (int i = 0; i < midArray02.size(); ++i) {
                                // 将每个字节转换为二进制形式的字符串，并打印
                                QString binaryString2 = QString::number(static_cast<unsigned char>(midArray02[i]), 2).rightJustified(8, '0');
                                // qDebug() << "Byte" << i << ":" << binaryString;
                                res2 += binaryString2;
                            }

                            if(res2.at(7) == '1')
                            {
                                b_knife01_Up_SLmt = true;
                            }
                            else if(res2.at(7) == '0')
                            {
                                b_knife01_Up_SLmt = false;
                            }
                            if(res2.at(6) == '1')
                            {
                                b_knife01_Down_SLmt = true;
                            }
                            else if(res2.at(6) == '0')
                            {
                                b_knife01_Down_SLmt = false;
                            }
                            if(res2.at(5) == '1')
                            {
                                b_knife02_Up_SLmt = true;
                            }
                            else if(res2.at(5) == '0')
                            {
                                b_knife02_Up_SLmt = false;
                            }
                            if(res2.at(4) == '1')
                            {
                                b_knife02_Down_SLmt = true;
                            }
                            else if(res2.at(4) == '0')
                            {
                                b_knife02_Down_SLmt = false;
                            }
                            if(res2.at(3) == '1')
                            {
                                b_knife03_Up_SLmt = true;
                            }
                            else if(res2.at(3) == '0')
                            {
                                b_knife03_Up_SLmt = false;
                            }
                            if(res2.at(2) == '1')
                            {
                                b_knife03_Down_SLmt = true;
                            }
                            else if(res2.at(2) == '0')
                            {
                                b_knife03_Down_SLmt = false;
                            }
                        }
                        else
                        {
                            qDebug()<<"读取报警信号操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }                

}

void ModbusControl::readVersoinDescription()
{
    // 测试数据（3000）   实际使用地址: 2060
    int readAdd = 3544 / 2;

    QModbusDataUnit readUnitH(QModbusDataUnit::HoldingRegisters,readAdd,2);

    if(auto* reply = (modbusClient->sendReadRequest(readUnitH,1))){
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,[reply, this]()
                    {
                        if(reply->error() == QModbusDevice::NoError)
                        {
                            const QModbusDataUnit resultUnit = reply->result();
                            vertion_Description = QString("%1").arg(combinationToFloat(resultUnit.value(0),resultUnit.value(1)));
                        }
                        else
                        {
                            qDebug()<<"读取报警信号操作失败"<<reply->errorString();
                        }

                        reply->deleteLater();
                    });
        }
        // reply->deleteLater();
    }
}



QString ModbusControl::IpAddr() const
{
    return m_IpAddr;
}

void ModbusControl::setIpAddr(const QString &newIpAddr)
{
    if (m_IpAddr == newIpAddr)
        return;
    m_IpAddr = newIpAddr;
    emit IpAddrChanged();
}

QString ModbusControl::PortNumber() const
{
    return m_PortNumber;
}

void ModbusControl::setPortNumber(const QString &newPortNumber)
{
    if (m_PortNumber == newPortNumber)
        return;
    m_PortNumber = newPortNumber;
    emit PortNumberChanged();
}

